// pages/order/order.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        img:"",
        title:"",
        date:"2021-10-10",
        time:"00:00",
        userName:"快乐在在",
        tel:"19162804615",
        message:"快乐没了"
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
       this.setData({
           img :options.img,
           title:options.title
       })
    },
    changeDate:function (options) {
        console.log(options.detail.value);
        this.setData({
            date:options.detail.value
        })
    },
    changeTime:function (options) {
        console.log(options.detail.value);
        this.setData({
            time:options.detail.value
        })
    },
    getName:function (options) {
        this.setData({
            userName:options.detail.value
        })
    },
    getTel:function (options) {
        this.setData({
            tel:options.detail.value
        })
    },
    getMessage:function (options) {
        this.setData({
           message:options.detail.value
        })
    },
    // 预约按钮
    submit:function (options) {
        var that = this
        console.log(options);
        // 获取用户的基本信息，授权
        wx.getUserProfile({
            desc: '验证用户信息',
            success:function (res) {
                console.log(res)
                // 用户点击确定后，自动将用户信息存入数据库中
               wx.request({
                 url: 'http://localhost:8080/sysUser/api/update',
                 method:"PUT",
                 data:{
                     "img":res.userInfo.avatarUrl,
                     "nickname":res.userInfo.nickName,
                     "sex":res.userInfo.gender,
                     "token":wx.getStorageSync('token')
                 },
                 success:function(res) {
                  //    实现预约功能
                  if(res.data.code == 200){
                      // 成功以后实现预约
                      wx.request({
                        url: 'http://localhost:8080/order/api/insert',
                        method:"POST",
                        data:{
                            "suName":that.data.title,
                            "dur":that.data.date+" "+that.data.time,
                            "wxName":that.data.userName,
                            "tel":that.data.tel,
                            "message":that.data.message,
                        },
                        success:function (res) {
                          //   判断预约是否成功
                          console.log("成功插入");
                        }
                      })
                  }else{
                      // 弹出预约失败消息
                  }
                 }
               })
            },
            fail:function (res) {
                
            }
          })
        
    }
})